package com.naiterui.ehp.bs.emr.entity.mongo;

import cn.hutool.core.collection.CollectionUtil;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.naiterui.ehp.bs.emr.utils.Constants;
import com.naiterui.ehp.bs.emr.utils.enums.ERelation;

/**
 * 患者填写病历
 *
 * @author wangzehao
 * @date 2018/11/21 11:49 AM
 * @since 1.0.0
 */
public class MedicalRecordPatient extends BaseMedicalRecordPatient {
    private static final long serialVersionUID = -8721331745264961650L;

    /**
     * 过敏药物
     *
     * @return
     */
    public String getMedicAllergysStr() {
        return this.getMedicAllergys().describe();
    }

    /**
     * 过往病史
     *
     * @return
     */
    public String getPastDiseasesStr() {
        return this.getPastDiseases().describe();
    }

    /**
     * 家族病史
     *
     * @return
     */
    public String getFamilyDiseasesStr() {
        List<MFamilyDisease> familyDiseases = super.getFamilyDiseases();
        if (CollectionUtil.isEmpty(familyDiseases)) {
            return null;
        }
        String familyDiseasesStr = "";
        for (MFamilyDisease mFamilyDisease : familyDiseases) {
            ERelation relateion = ERelation.val(mFamilyDisease.getMember());
            MSelectOrOthers disease = mFamilyDisease.getDisease();
            if (relateion == null) {
                continue;
            }
            if (StringUtils.isNotEmpty(familyDiseasesStr)) {
                familyDiseasesStr += StringUtils.LF;
            }
            String temp = relateion.getName() + ": " + disease.getDefaultNames();
            familyDiseasesStr += temp;

        }
        return familyDiseasesStr;
    }

    /**
     * 遗传病
     *
     * @return
     */
    public String getHereditaryDiseasesStr() {
        return this.getHereditaryDiseases().describe();
    }

    /**
     * 吸烟情况
     *
     * @return
     */
    public String getSmokeStr() {
        MSmoke smoke = this.getSmoke();
        String smokeStatus = smoke.getStatus();
        if (StringUtils.isEmpty(smokeStatus)) {
            return null;
        }
        int istatus = Integer.parseInt(smokeStatus);
        // 非吸烟
        if (istatus == MSmoke.SMOKE_STATUS_YES) {
            StringBuilder builder = new StringBuilder();
            builder.append(Constants.SMOKE_MAP.get(istatus));
            String smokeStart = smoke.getSmokeStart();
            if (StringUtils.isNotEmpty(smokeStart)) {
                builder.append(StringUtils.LF);
                builder.append("开始吸烟年龄：");
                builder.append(smokeStart);
                builder.append("岁");
            }
            String perdayNum = smoke.getPerdayNum();
            if (StringUtils.isNotEmpty(perdayNum)) {
                builder.append(StringUtils.LF);
                builder.append("每日吸烟量：");
                builder.append(perdayNum);
                builder.append("支");
            }
            return builder.toString();
        }
        return Constants.SMOKE_MAP.get(istatus);
    }

    /**
     * 饮酒情况
     *
     * @return
     */
    public String getDrinkStr() {
        MDrink drink = super.getDrink();
        Integer drinkFrequency = drink.getFrequency();
        if (drinkFrequency == null) {
            return null;
        }
        StringBuilder builder = new StringBuilder();
        builder.append("饮酒频率:");
        builder.append(Constants.DRINK_FREQUENCY_MAP.get(drinkFrequency));
        if (drinkFrequency == MDrink.DRINK_FREQUENCY_NO) {
            return builder.toString();
        }
        if (StringUtils.isNotEmpty(drink.getPerdayNum())) {
            builder.append(StringUtils.LF);
            builder.append("每日饮酒量：");
            builder.append(drink.getPerdayNum());
            builder.append("两");
        }
        if (StringUtils.isNotEmpty(drink.getDrinkStart())) {
            builder.append(StringUtils.LF);
            builder.append("饮酒开始年龄：");
            builder.append(drink.getDrinkStart());
            builder.append("岁");
        }
        // 判断戒酒类型
        if (StringUtils.isNotEmpty(drink.getDrinkStatus())) {
            builder.append(StringUtils.LF);
            int drinkStatus = Integer.parseInt(drink.getDrinkStatus());
            builder.append(Constants.DRINK_STATUS_MAP.get(drinkStatus));
            if (drinkStatus == MDrink.DRINK_STATUS_NO) {
                if (StringUtils.isNotEmpty(drink.getStopAge())) {
                    builder.append(",");
                    builder.append("戒酒年龄：");
                    builder.append(drink.getStopAge());
                    builder.append("岁");
                }
            }
        }

        // 饮酒类型
        MSelectOrOthers wines = drink.getWines();
        if (wines != null) {
            builder.append(StringUtils.LF);
            builder.append("饮酒类型：");
            builder.append(wines.getDefaultNames());
        }

        return builder.toString();
    }

}
